/**
 * @Description 公告管理业务实现
 * @author 20155870 杨润增
 * @create 2018-05-13 21:44
 **/
package com.campus_information_portal.service.impl;

import com.campus_information_portal.dao.NoticeDao;
import com.campus_information_portal.entity.Notice;
import com.campus_information_portal.entity.NoticeTeacher;
import com.campus_information_portal.service.NoticeService;
import com.campus_information_portal.util.Message;
import com.campus_information_portal.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 20155870 杨润增
 * @className NoticeImpl
 * @Description 公告管理业务实现
 * @create 2018-05-13 21:44
 **/
@Service
public class NoticeImpl implements NoticeService {
    @Autowired
    private NoticeDao noticeDao;


    @Override
    public Message addNotice(Notice notice) {

        int flag=noticeDao.addNotice(notice);
        if(flag==1){
            return Message.success();
        }
        return Message.fail().add("1201","增加失败");
    }

    @Override
    public Message deleteNotice(int noticeId) {
        int flag=noticeDao.deleteNotice(noticeId);
        if (flag == 1) {
            return Message.success();
        }
        return Message.fail().add("1202","删除失败");
    }

    @Override
    public Message queryAllNotice() {
        List<NoticeTeacher> noticeList=noticeDao.queryAllNotice();
        if(noticeList.size()>0){
            return Message.success().add("noticeList",noticeList);
        }
        return Message.fail().add("1203","查询失败");
    }

    @Override
    public Message updateNotice(Notice notice) {
        int noticeId=notice.getNoticeId();
        String noticeContent=notice.getNoticeContent();
        String noticeTitle=notice.getNoticeTitle();
        int flag=noticeDao.updateNotice(noticeId,noticeTitle,noticeContent);
        if(flag==1){
            return Message.success();
        }
        return Message.fail().add("1204","更新失败");
    }

    @Override
    public Message queryNoticeById(int noticeId) {
        NoticeTeacher noticeTeacher=noticeDao.queryNoticeById(noticeId);
        if(noticeTeacher!=null){
            return Message.success().add("noticeTeacher",noticeTeacher);
        }
        return Message.fail().add("1205","查询失败");
    }
}
